package com.example;

import javax.microedition.khronos.opengles.GL10;

import com.step.Step;
import com.step.Step.Dimension;
import com.step.graphic.Texture;
import com.step.mesh.Face;
import com.step.mesh.Mesh;
import com.step.sprite.Sprite.RenderType;

public class TextureExample extends BaseExample{
	Mesh mesh;
	Texture texture;
	
	@Override
	public void create() {
		super.create();
		mesh = new Mesh(Dimension.d2d, 4, 2);
		mesh.addVertex(-1, -1, (short)255, (short)255, (short)255, (short)255, 0, 1);
		mesh.addVertex(1, -1, (short)255, (short)255, (short)255, (short)255, 1, 1);
		mesh.addVertex(1, 1, (short)255, (short)255, (short)255, (short)255, 1, 0);
		mesh.addVertex(-1, 1, (short)255, (short)255, (short)255, (short)255, 0, 0);
		// 添加索引面，一个矩形由两个三角形面组成
		mesh.addFace(new Face(0, 1, 2));
		mesh.addFace(new Face(0, 2, 3));
		// 初始化纹理
		texture = new Texture(Step.files.internal("textures/logo.png"), false);
		Step.dimension = Dimension.d2d;
	}

	@Override
	public void update() {
		GL10 gl = Step.gl;
		gl.glClearColor(1, 1, 1, 1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
		gl.glEnable(GL10.GL_TEXTURE_2D);
		texture.bind();
		mesh.render(gl,RenderType.TRIANGLES);	
		gl.glDisable(GL10.GL_TEXTURE_2D);
	}
	
}
